﻿namespace WMS6.Web.Administration
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class SysSetting : BasePage
    {
        protected Button btnGoBack;
        protected Button btnSave;
        protected DropDownList ddlValue;
        protected HtmlForm F1071;
        protected HtmlInputHidden hdnFrom;
        protected Label lblDescr;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblSysSettingID;
        protected Label lblValue;
        protected Label lblValueDefault;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtDescr;
        protected TextBox txtSysSettingID;
        protected TextBox txtValue;
        protected TextBox txtValueDefault;
        protected UpdatePanel up1;

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("SysSettingQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("SysSettingList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SysSettingInfo sysSetting = new SysSettingInfo();
                if (base.DataEntityViewState != null)
                {
                    sysSetting = base.DataEntityViewState as SysSettingInfo;
                }
                if (this.txtValue.Visible)
                {
                    sysSetting.Value = this.txtValue.Text.Trim();
                }
                else
                {
                    sysSetting.Value = this.ddlValue.SelectedValue;
                }
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(sysSetting, "SYS_SETTING") + base.GetGlobalMsgResource("F1700_001");
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1700_002") + ex.Message;
            }
        }

        private void LoadData()
        {
            if (base.Request.QueryString["ID"] != null)
            {
                this.SetSysSetting2From();
            }
            if (base.Request.QueryString["from"] != null)
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetSysSetting2From()
        {
            try
            {
                string SysSettingID = base.Request.QueryString["ID"].ToString();
                SysSettingInfo sysSetting = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(SysSettingID, "SYS_SETTING") as SysSettingInfo;
                base.DataEntityViewState = sysSetting;
                this.txtSysSettingID.Text = sysSetting.SysSettingID;
                this.txtDescr.Text = sysSetting.Descr;
                this.ddlValue.SelectedValue = sysSetting.Value;
                this.txtValue.Text = sysSetting.Value;
                if (sysSetting.ParamType == "F")
                {
                    this.txtValue.Visible = false;
                    this.ddlValue.Visible = true;
                }
                else
                {
                    this.txtValue.Visible = true;
                    this.ddlValue.Visible = false;
                }
                this.txtValueDefault.Text = sysSetting.ValueDefault;
                if (sysSetting.IsModifiable == "Y")
                {
                    this.txtValue.Enabled = true;
                    this.ddlValue.Enabled = true;
                }
                else
                {
                    this.txtValue.Enabled = false;
                    this.ddlValue.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }
    }
}

